<?php
class TimechecksController extends AppController {

	var $name = 'Timechecks';
	
	/**
	 * 
	 * @param unknown_type $id
	 * @param unknown_type $score
	 * @param unknown_type $submitted_time
	 * @return $score
	 */
	function check ($id,$score,$submitted_time){
		
		if ($id!=null&&$score!=null&&$submitted_time!=null)
		$timecheck=$this->Timecheck->read (null,$id);
		//debug ($timecheck);
		$type=$timecheck['Timecheck']['time_check_type'];
		$time_num1=$timecheck['Timecheck']['time_number1'];
		$time_num2=$timecheck['Timecheck']['time_number2'];
		
		if ($type=='TRI'){
			if ($submitted_time>$time_num1)
			$score=0;
		}
		if ($type=='REC'){
			if ($submitted_time>=$time_num1) $score=0;
			else $score=$score*(1.0-$submitted_time/$time_num1);
		}
		if ($type=='TRAP'){
			if ($submitted_time>=$time_num1+$time_num2) $score=0;
			else if ($submitted_time>$time_num1) 
			$score=$score*(1.0-($submitted_time-$time_num1)/$time_num2);
		}
		//debug ($score);
		return $score;		
	}
}
